package org.springframework.remoting.jsonrpc;

import java.text.DecimalFormat;

import org.jabsorb.serializer.SerializerState;
import org.jabsorb.serializer.UnmarshallException;
import org.jabsorb.serializer.impl.StringSerializer;

public class ObjectSerializer extends StringSerializer {

	public ObjectSerializer() {
		super();
	}

	public Class[] getJSONClasses() {
		return new Class[0];
	}

	public Class[] getSerializableClasses() {
		return new Class[0];
	}

	public boolean canSerialize(Class clazz, Class jsonClazz) {
		return clazz.getName().equals("java.lang.Object");
	}

	public Object unmarshall(SerializerState state, Class clazz, Object json) throws UnmarshallException {
		DecimalFormat format = new DecimalFormat("#.#");
		format.setDecimalSeparatorAlwaysShown(false);
    	if ( json instanceof Double ||
    			json instanceof Integer ||
    			json instanceof Float ||
    			json instanceof Long ||
    			json instanceof Short)
    		return format.format(json);
		return super.unmarshall(state, clazz, json);
	}

	
}
